<!--

Copyright 2015 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<!doctype html>
<html>
  {% include "templates/_includes/head.html" %}
<body>

  {% include "templates/_includes/navigation.html" %}
  {% include "templates/_includes/location.html" %}
  {% include "templates/_includes/project.html" %}

  <main class="main-view">

    {% if projects.count() == 0 %}
      <!-- TODO(paullewis) Make a nicer message -->
      Make a new Project.
    {% else %}
      <table class="projects-list mdl-data-table mdl-js-data-table mdl-shadow--2dp">
        <thead>
          <tr>
            <th class="mdl-data-table__cell--non-numeric">Name</th>
            <th class="mdl-data-table__cell--non-numeric">Secret</th>
            <th class="mdl-data-table__cell--non-numeric">Edit</th>
            <th class="mdl-data-table__cell--non-numeric">Delete</th>
          </tr>
        </thead>
        <tbody>
          {% for project in projects %}

            {% if (user_is_admin or
                (not project.visible_to_owner_only) or
                (project.visible_to_owner_only and user_email == project.owner)) %}

            <tr>
              <td class="mdl-data-table__cell--non-numeric">
                <a href="./{{ project.key.integer_id() }}/">{{ project.name }}</a>
                {% if project.visible_to_owner_only %}
                [Private]
                {% endif %}
              </td>
              <td class="mdl-data-table__cell--non-numeric projects-options">
                <div id="project-{{ project.key.integer_id() }}-secret" class="project-secret">{{ project.secret }}</div>
                <button for="project-{{ project.key.integer_id() }}-secret" class="project-secret-copy mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
                  <i class="material-icons">content_copy</i>
                </button>
              </td>
              <td class="mdl-data-table__cell--non-numeric projects-options">
                <button
                  data-project-key="{{ project.key.integer_id() }}"
                  data-project-name="{{ project.name }}"
                  data-project-visible-only-to-owner="{{ project.visible_only_to_owner }}"
                  class="project-edit mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
                  <i class="material-icons">mode_edit</i>
                </button>
              </td>

              <td class="mdl-data-table__cell--non-numeric projects-options">
                <button data-project-key="{{ project.key.integer_id() }}" class="project-delete mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
                  <i class="material-icons">delete</i>
                </button>
              </td>
            </tr>

            {% endif %}
          {% endfor %}
        </tbody>
      </table>
    {% endif %}

  </main>

  {% include "templates/_includes/toaster.html" %}

  <script src="/scripts/bigrig.js"></script>
  <script src="/scripts/project.js"></script>
</body>
</html>
